package application;

import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;
import javafx.event.ActionEvent; 

import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import db.DB_tools;
import base.Person;
import base.Manager;
import base.Staff;
import javafx.scene.control.*;;

public class StaffinfoController implements Initializable{
	@FXML
	private Button bstaffinfo;
	@FXML
	private Button bcheckattendance;
	@FXML
	private Button battendance_st;
	@FXML
	private Button bdaily_ass;
	@FXML
	private Button bbulletin;
	@FXML
	private Button blogout;
	
	@FXML
	private Label name;
	@FXML
	private Label position;
	@FXML
	private Label email;
	@FXML
	private Label gender;
	@FXML
	private Label level;
	
	private Main application;
	
	Person p=new Manager();
	
	@FXML
	public void toBulletin(ActionEvent event){
		if("Manager".equals(p.getLevel())){
		    Manager m = (Manager)p;
			application.gotoaddBulletin(m);
		}
		else{
			application.gotoBulletin(p);
		}
		
	}
	
	@FXML
	public void gotoAssignment(ActionEvent event)
	{
		if("Manager".equals(p.getLevel()))
		{
			Manager m=(Manager)p;
			application.gotoaddAssignment(m);
		}
		else{
			application.gotoAssignment(p);
		}
	}
	
	public void setApp(Main application){  
        this.application = application;  
    }  
	
	public void showinfo(String n, int i){
		
		System.out.println("if success:"+p.getName());
		Map<String, String> row=new HashMap<String, String>();
		row=db.DB_tools.getOneUser(n, i);
		name.setText(row.get("name"));
		position.setText(row.get("position"));
		email.setText(row.get("email"));
		gender.setText(row.get("sex"));
		level.setText(row.get("level"));
	}
	
	@FXML
	public void bcheckattendance(ActionEvent event)
	{
		application.gotoCheckAttendance(p);	
	}
	

	@FXML
	public void bstaffinfo(ActionEvent event)
	{
		if("Manager".equals(p.getLevel()))
		{
			Manager m=(Manager)p;
			System.out.println("I'm Manager");
			application.gotoNamelist(m);
		}
		else
		{
			application.gotoStaffinfo(p);
		}
	}
	
	@FXML
	public void bdaily_ass(ActionEvent event)
	{
		if("Manager".equals(p.getLevel())){
		    Manager m = (Manager)p;
			application.gotoaddAssignment(m);
		}
		else{
			application.gotoAssignment(p);
		}
	}
	
	@FXML
	public void toAttendance(ActionEvent event){
		if("Manager".equals(p.getLevel())){
		    Manager m = (Manager)p;
			application.gotonamelist(m);
		}
		else{
			String s = String.valueOf(p.getID());
			application.gotoworkdayinfo(p, s);
		}
	}
	
	
	
	@Override
	public void initialize(URL location, ResourceBundle resources) {
		// TODO Auto-generated method stub
		
	}

}
